<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="关键字搜索" prop="search">
        <el-input v-model="queryParams.search" placeholder="关键字搜索" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

 

    <el-table v-loading="loading" :data="giftList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="房间id" align="center" prop="roomId" />
      <el-table-column label="福袋标题" align="center" prop="name" />
      <el-table-column label="福袋金额" align="center" prop="luckyBagMoney" />
      <el-table-column label="中奖人数" align="center" prop="winnerNum"/>
      <el-table-column label="0所有1粉丝" align="center" prop="isPart" />
      <el-table-column label="参与方式" align="center" prop="partWay" />
      <el-table-column label="弹幕内容" align="center" prop="danmuContent" />
      <el-table-column label="倒计时秒" align="center" prop="countDownTime" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="总金额" align="center" prop="totalMoney" />
      <el-table-column label="备注" align="center" prop="remark" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">



          <el-button size="mini" type="text"  @click="handleUpdate(scope.row, 1)"
            v-hasPermi="['dynamic:luckBag:check']">通过</el-button>
          <el-button size="mini" type="text"  @click="handleUpdate(scope.row,2)"
            v-hasPermi="['dynamic:luckBag:check']">拒绝</el-button>




      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.size"
      @pagination="getList" />

    <!-- 添加或修改礼物对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="礼物名称" prop="giftName">
          <el-input v-model="form.giftName" placeholder="请输入礼物名称" />
        </el-form-item>
        <el-form-item label="礼物图片" prop="giftImg">
          <ImageUpload @input="uploadSuccess" :value="form.giftImg" />
        </el-form-item>
        <el-form-item label="礼物价格" prop="giftPrice">
          <el-input v-model="form.giftPrice" placeholder="请输入礼物价格" />
        </el-form-item>

        <el-form-item label="礼物类型" prop="giftType">
          <el-select v-model="form.giftType">
            <el-option label="普通礼物" :value="0"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="礼物特效类型" prop="type">
          <el-select v-model="form.type">
            <el-option label="无特效" :value="0"></el-option>
            <el-option label="中间特效礼物" :value="1"></el-option>
            <el-option label="全屏特效礼物" :value="2"></el-option>
            <el-option label="自定义礼物" :value="3"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="画面显示时间" prop="giftTime">
          <el-input v-model="form.giftTime" placeholder="画面显示时间" />
        </el-form-item>
        <!-- <el-form-item label="平台抽取比例" prop="takePercent">
          <el-input v-model="form.takePercent" placeholder="请输入平台抽取比例" />
        </el-form-item> -->
        <el-form-item label="特效视频" prop="video">
          <FileUpload @input="uploadVideoSuccess" />

          <video :src="form.video" controls style="width: 160px; height: 160px" />
        </el-form-item>
        <el-form-item label="礼物排序" prop="sort">
          <el-input v-model="form.sort" placeholder="请输入礼物排序" />
        </el-form-item>
        <!-- <el-form-item label="礼物标识" prop="giftMark">
          <el-input v-model="form.giftMark" placeholder="请输入礼物标识" />
        </el-form-item> -->
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { luckBagCheck, luckBagListPage } from "@/api/room/room";
import FileUpload from "@/components/FileUpload/index.vue"

export default {
  name: "Gift",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 礼物表格数据
      giftList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        page: 1,
        size: 10,
        giftType: '',
        search: ''
      },
      // 表单参数
      form: {
        giftType: 0
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    uploadVideoSuccess(res) {
      this.form.video = res;
    },
    uploadSuccess(res) {
      this.form.giftImg = res;
    },
    /** 查询礼物列表 */
    getList() {
      this.loading = true;
      luckBagListPage(this.queryParams).then(response => {
        this.giftList = response.data.data;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
       id:'',
       status:'',
       remark:''
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加礼物";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.form.id=row.id;
      this.form.status=status;
      this.open=true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          addOrEditGift(this.form).then(response => {
            this.$modal.msgSuccess("新增成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除礼物编号为"' + ids + '"的数据项？').then(function () {
        return delGift(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('user/gift/export', {
        ...this.queryParams
      }, `gift_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
